package com.nokia.examplegame;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;

public class BackgroundTiledLayer extends TiledLayer {

	static int TYPE1 = 1;

	static int TYPE2 = 2;

	static int TYPE3 = 3;

	static int TILE_WIDTH = 32;

	static int TILE_HEIGHT = 64;

	static int TILE_REPEAT = 10;

	static int TOP_Y;

	static int COLUMNS;

	public BackgroundTiledLayer(Image image, int displayWidth, int displayHeight)
			throws Exception {
		super(setColumns(displayWidth), 1, image, TILE_WIDTH, TILE_HEIGHT);
		TOP_Y = displayHeight - TILE_WIDTH;
		setPosition(-(TILE_WIDTH * TILE_REPEAT), TOP_Y);
		boolean insertType2 = true;
		for (int i = 0; i < COLUMNS; i++) {
			if ((i % TILE_REPEAT == 0) || (i % TILE_REPEAT == 2)) {
				if (insertType2) {
					setCell(i, 0, TYPE3);
					insertType2 = false;
				} else {
					setCell(i, 0, TYPE2);
					insertType2 = true;
				}
			} else {
				setCell(i, 0, TYPE1);
			}
		}
	}

	public void reset() {
		setPosition(-(TILE_WIDTH * TILE_REPEAT), TOP_Y);
	}

	static int setColumns(int screenWidth) {
		COLUMNS = ((screenWidth / 20) + 1) * 10;
		return COLUMNS;
	}

}